﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
 

namespace FXnaGis
{
    public  class GDIHelper
    {

        /// <summary>
        /// 绘制X方向坐标轴，直接取坐标，速度快一点
        /// </summary>
        /// <param name="g"></param>
        /// <param name="ptStart"></param>
        /// <param name="ptEnd"></param>
        public static void DrawXAxisArrow( Graphics g, Pen pen, Point ptStart, Point ptEnd)
        {

            //绘制直线

            g.DrawLine(pen,ptStart,ptEnd);

            //绘制三角形

            int xLength=ptEnd.X - ptStart.X;

            int xPos=ptStart.X + (int)((xLength) * 0.7);

            Point ptTop =new Point(xPos,(ptStart.Y+(int)(xLength *0.3*0.25)));

            Point ptDown = new Point(xPos, (ptStart.Y - (int)(xLength * 0.3 * 0.25)));

            List<Point> pts=new List<Point> ();
            pts.Add (ptTop);
            pts.Add (ptDown);
            pts.Add (ptEnd);

            Brush b = new SolidBrush(pen.Color);

            g.FillPolygon(b, pts.ToArray());

            b.Dispose();



        }


        public static void DrawYAxisArrow(Graphics g, Pen pen, Point ptStart, Point ptEnd)
        {

            //绘制直线

            g.DrawLine(pen, ptStart, ptEnd);

            //绘制三角形

            int yLength = ptEnd.Y - ptStart.Y;

            int yPos = ptStart.Y + (int)((yLength) * 0.7);


            //左点

            Point ptTop = new Point(ptStart.X-(int)(yLength*0.3*0.25), yPos);

            Point ptDown = new Point(ptStart.X + (int)(yLength * 0.3 * 0.25), yPos);

            List<Point> pts = new List<Point>();
            pts.Add(ptTop);
            pts.Add(ptDown);
            pts.Add(ptEnd);

            Brush b = new SolidBrush(pen.Color);

            g.FillPolygon(b, pts.ToArray());

            b.Dispose();

 
        }




        /// <summary>
        /// 绘制类似于3dsmax的包围盒子
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        public static void DrawBoundingBox(Graphics g,Pen p, Rectangle rect)
        {
           
            //具体执行标准为 边线长度的0.25倍

            int xlen =(int)(rect.Width * 0.25f);
            int ylen =(int) (rect.Height * 0.25f);


            //顺时针方向

            //绘制top

            g.DrawLine(p,rect.Left,rect.Top,rect.Left +xlen,rect.Top);

            g.DrawLine(p,rect.Right,rect.Top,rect .Right-xlen,rect.Top);


            //绘制right

            g.DrawLine(p,rect.Right,rect.Top,rect.Right,rect.Top +ylen);

            g.DrawLine(p,rect.Right,rect.Bottom,rect.Right,rect.Bottom-ylen);


            //绘制bottom

            g.DrawLine(p,rect.Right,rect.Bottom,rect.Right-xlen,rect.Bottom);

            g.DrawLine(p,rect.Left+xlen,rect.Bottom,rect.Left,rect.Bottom);

            //绘制left

            g.DrawLine(p,rect.Left,rect .Bottom,rect.Left,rect.Bottom-ylen);

            g.DrawLine(p,rect.Left,rect.Top+ylen,rect.Left,rect.Top);



 
        }


    }
}
